package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    @Operation(summary = "获取排行榜")
    @GetMapping("/findRankingList/{category1Id}/{ranking}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable("category1Id") Long category1Id,@PathVariable("ranking") String ranking){
        List<AlbumInfoIndex> albumInfoIndexList = searchService.findRankingList(category1Id, ranking);

        return Result.ok(albumInfoIndexList);
    }
    //先写进缓存中，才可以进行获取排行榜
    @Operation(summary = "更新排行榜")
    @GetMapping("updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }
    /**
     * 关键字自动补全
     * @param keyword
     * @return
     */
    @Operation(summary = "关键字自动补全")
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable("keyword") String keyword){
        List<String> suggestList=searchService.completeSuggest(keyword);
        return Result.ok(suggestList);
    }

    /**
     * 查询指定一级分类下热门排行专辑
     * @param category1Id
     * @return
     */
    @Operation(summary = "查询指定一级分类下热门排行专辑")
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable("category1Id") Long category1Id){
        List<Map<String, Object>> mapList=searchService.channel(category1Id);
        return Result.ok(mapList);
    }
    /**
     * 专辑检索
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "专辑检索")
    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo searchResponseVo= searchService.search(albumIndexQuery);
        return  Result.ok(searchResponseVo);
    }
    /**
     * 批量上架专辑
     * @return
     */
    @Operation(summary = "批量上架专辑")
    @GetMapping("/batchUpperAlbum")
    public Result batchUpperAlbum(){
        //调用服务层方法
        for (Long i = Long.valueOf(1); i <= 1500; i++) {
            searchService.upperAlbum(i);
        }
        return Result.ok();
    }
    /**
     * 上传专辑
     * @param albumId
     * @return
     */
    @Operation(summary = "上传专辑")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){

        searchService.upperAlbum(albumId);
        //调用服务层方法
        return Result.ok();
    }
    /**
     * 上传专辑
     * @param albumId
     * @return
     */
    @Operation(summary = "下架专辑")
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){

        searchService.lowerAlbum(albumId);
        //调用服务层方法
        return Result.ok();
    }
}

